﻿using System;
using System.Windows.Forms;
using DXApplicationTangche.UC.项目成果管理.service;
using DXApplicationTangche.UC.生产计划.生产批生产.service;
using DXApplicationTangche.UC.下单MTO.Service;
using DXApplicationTangche.UC.门店出入库.Service;

namespace DXApplicationTangche.UC.项目成果管理.在制品管理
{
    public partial class FormVI质检提交新 : DevExpress.XtraEditors.XtraForm
    {
        private String code { get; set; }
        private String barcode { get; set; }

        public FormVI质检提交新(String barcode, String code)
        {
            InitializeComponent();
            this.barcode = barcode;
            this.code = code;
        }

        private void textBox扫描_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (String.IsNullOrEmpty(this.textBox扫描.Text))
                {
                    MessageBox.Show("无扫描信息");
                    return;
                }
                //判断扫描的工牌是否正确
                String mnemonic = 项目成果Service.get判断扫描员工码是否正确(this.textBox扫描.Text.Trim());
                if (String.IsNullOrWhiteSpace(mnemonic))
                {
                    this.textBox扫描.Clear();
                    MessageBox.Show("扫描员工码错误，请重新扫描");
                    return;
                }
                try
                {
                    String stepName = "";
                    if ("01.0005".Equals(this.code))
                    {
                        stepName = BarcodeWipInstanceConsts.HALF_PRODUCT_INSPECTION;
                    }
                    else if ("01.0005.01".Equals(this.code))
                    {
                        stepName = BarcodeWipInstanceConsts.FIRST_PRODUCT_INSPECTION;
                        //  成品一检入待检仓
                        出入库Service.garmentQCWaitStockIn(this.barcode);
                    }
                    else if ("01.0007".Equals(this.code))
                    {
                        stepName = BarcodeWipInstanceConsts.FINISHED_PRODUCT_INSPECTION;
                    }
                    if (!String.IsNullOrEmpty(this.barcode))
                    {
                        //  生产工序执行
                        PlainMessageResult plainMessageResult = 生产批生产Service.wipBarcodeScan(this.barcode, stepName, mnemonic);
                        if (!"200".Equals(plainMessageResult.errorCode))
                        {
                            MessageBox.Show(plainMessageResult.errorMessage);
                            this.Close();
                            return;
                        }
                        else
                        {
                            MessageBox.Show("操作完成");
                            this.Close();
                        }
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }

            }
        }
    }
}